package com.shm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.entity.ProductLike;
import com.ruoyi.common.core.domain.entity.ProductRead;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.shm.service.IProductReadService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品——阅读Controller
 *
 * @author dam
 * @date 2023-08-10
 */
@RestController
@RequestMapping("/market/read")
public class ProductReadController extends BaseController {
    @Autowired
    private IProductReadService productReadService;

    /**
     * 查询商品——阅读列表
     */
    @PreAuthorize("@ss.hasPermi('market:read:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProductRead productRead) {
        startPage();
        List<ProductRead> list = productReadService.list(new QueryWrapper<ProductRead>(productRead));
        return getDataTable(list);
    }

    /**
     * 导出商品——阅读列表
     */
    @PreAuthorize("@ss.hasPermi('market:read:export')")
    @Log(title = "商品——阅读", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductRead productRead) {
        List<ProductRead> list = productReadService.list(new QueryWrapper<ProductRead>(productRead));
        ExcelUtil<ProductRead> util = new ExcelUtil<ProductRead>(ProductRead.class);
        util.exportExcel(response, list, "商品——阅读数据");
    }

    /**
     * 获取商品——阅读详细信息
     */
    @PreAuthorize("@ss.hasPermi('market:read:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(productReadService.getById(id));
    }

    /**
     * 新增商品——阅读
     */
    @PreAuthorize("@ss.hasPermi('market:read:add')")
    @Log(title = "商品——阅读", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductRead productRead) {
        return toAjax(productReadService.save(productRead));
    }

    /**
     * 修改商品——阅读
     */
    @PreAuthorize("@ss.hasPermi('market:read:edit')")
    @Log(title = "商品——阅读", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductRead productRead) {
        return toAjax(productReadService.updateById(productRead));
    }

    /**
     * 删除商品——阅读
     */
    @PreAuthorize("@ss.hasPermi('market:read:remove')")
    @Log(title = "商品——阅读", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(productReadService.removeByIds(ids));
    }
}
